﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Globalization;

namespace DreamShieldPublishRetriever
{
    /*
     * Subset du fichier complet, juste histoire
     * d'avoir les infos de téléchargement
     * */

    [Serializable]
    [XmlRoot("ApplicationUpdateProduct")]
    public class OnlineProductSubset
    {
        static XmlSerializer serializer = new XmlSerializer(typeof(OnlineProductSubset));

        public static XmlSerializer GetSerializer()
        {
            return serializer;
        }

        public OnlineProductSubset()
        {
            Versions = new List<OnlineProductUpdateSubset>();
        }

        public virtual Guid ApplicationGuid { get; set; }

        public virtual string ApplicationName { get; set; }

        public virtual string ApplicationURL { get; set; }

        [XmlArray("Versions")]
        [XmlArrayItem("ApplicationUpdateRecord")]
        public virtual List<OnlineProductUpdateSubset> Versions{get;set;}
    }

    [Serializable]
    public class OnlineProductUpdateSubset : IComparable<OnlineProductUpdateSubset>
    {
        public virtual OnlineProductUpdateSubset_Version CurrentApplicationVersion { get; set; }

        public virtual bool CurrentVersionDownloadAvailable { get; set; }

        public virtual OnlineProductUpdateSubset_DownloadInfo CurrentVersionDownloadInfo { get; set; }

        #region IComparable<OnlineProductSubset> Membres

        public virtual int CompareTo(OnlineProductUpdateSubset other)
        {
            if (CurrentApplicationVersion == null)
            {
                if (other.CurrentApplicationVersion == null)
                    return 0;
                else
                    return -1;
            }
            else
            {
                return CurrentApplicationVersion.CompareTo(other.CurrentApplicationVersion);
            }
        }

        #endregion
    }

    [Serializable]
    public class OnlineProductUpdateSubset_Version : IComparable<OnlineProductUpdateSubset_Version>
    {
        [XmlAttribute]
        public virtual int Major { get; set; }

        [XmlAttribute]
        public virtual int Minor { get; set; }

        [XmlAttribute]
        public virtual int Build { get; set; }

        [XmlAttribute]
        public virtual int Revision { get; set; }

        public virtual Version StandardVersion
        {
            get
            {
                return new Version(Major, Minor, Build, Revision);
            }
        }

        #region IComparable<OnlineProductUpdateSubset_Version> Membres

        public virtual int CompareTo(OnlineProductUpdateSubset_Version other)
        {
            if (other == null)
                return 1;
            else
            {
                return StandardVersion.CompareTo(other.StandardVersion);
            }
        }

        #endregion
    }

    [Serializable]
    public class OnlineProductUpdateSubset_DownloadInfo
    {
        public virtual string ItemDownloadUrl { get; set; }
    }
}
